// 新增施工班组合同

<template>
  <div class="add_wrap">
    <div class="add_from">
      <div class="title">
        基本信息
      </div>

      <!-- 表单 -->
      <el-form ref="form" :model="contractForm" label-width="80px">
        <el-form-item label="合同编号">
          <el-input v-model="contractForm.contractNo"></el-input>
        </el-form-item>
        <el-form-item label="合同名称">
          <el-input v-model="contractForm.contractName"></el-input>
        </el-form-item>
        <el-form-item label="关联项目">
          <el-select v-model="contractForm.relation" placeholder="请选择关联项目">
            <el-option v-for="item in relationList" :key="item.id" :value="item.id" :label="item.name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="乙方单位">
          <el-select v-model="contractForm.PartBComplany" placeholder="请选择施工单位">
            <!-- buildTeamList -->
            <el-option v-for="(v,i) in buildTeamList" :key="i" :label="v.nameOfConstructionTeam" :value="v.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="乙方负责人">
          <el-input v-model="contractForm.leading"></el-input>
        </el-form-item>
        <el-form-item label="乙方联系电话">
          <el-input v-model="contractForm.partBPhone"></el-input>
        </el-form-item>
        <el-form-item label="合同开工日期">
          <el-date-picker type="date" placeholder="选择日期" v-model="contractForm.planBeginDate" style="width: 100%;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同竣工日期">
          <el-date-picker type="date" placeholder="选择日期" v-model="contractForm.planOverDate" style="width: 100%;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同金额">
          <el-input v-model="contractForm.heTongMoney"></el-input>
        </el-form-item>
        <el-form-item label="计价方式">
          <el-select v-model="contractForm.valuationId" placeholder="请选择计价方式">
            <el-option v-for="(v,i) in pricingList" :key="i" :label="v.valuation" :value="v.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="经办人">
          <el-select v-model="contractForm.createEmployeeId" placeholder="请选择经办人">
            <el-option v-for="(v,i) in staffList" :key="i" :label="v.name" :value="v.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="经办部门">
          <el-select v-model="contractForm.deptName" placeholder="请选择部门">
            <el-option v-for="(v,i) in depList" :key="i" :label="v.deptName" :value="v.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="签约日期">
          <el-date-picker type="date" placeholder="选择日期" v-model="contractForm.qianYueDate" style="width: 100%;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否申请盖章">
          <el-switch v-model="contractForm.chapterStatus"></el-switch>
        </el-form-item>
        <el-form-item label="付款备注">
          <el-input type="textarea" v-model="contractForm.paymentRemark"></el-input>
        </el-form-item>
        <el-form-item label="用印类型">
          <el-select v-model="contractForm.chapterWithTypeId" placeholder="请选择用印">
            <el-option v-for="(v,i) in printingType" :key="i" :label="v.type" :value="v.id">
            </el-option>
          </el-select>
        </el-form-item>
        <div class="upload">
          <div class="upload_tit">
            合同附件
          </div>
          <el-form-item label="相关附件">
            <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/"
              :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :limit="3"
              :on-exceed="handleExceed" :file-list="fileList">
              <el-button size="small" type="primary">+点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
          </el-form-item>
        </div>
        <el-form-item class="btn">
          <el-button type="primary" @click="keep">保存</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<style src="./style/AddContract.css">
</style>
<script>
import typeMixin from "../../../../minxins/contractMixin/typeMixin";
export default {
  mixins: [typeMixin],
  data () {
    return {

      // 附件列表
      fileList: [
      ],
      // 新增施工班组合同表单
      contractForm: {
        // 合同编号
        contractNo: '',
        // 合同名称
        contractName: '',
        // 关联项目---------
        relation: '',
        // 乙方单位---------
        PartBComplany: '',
        // 乙方负责人-------
        leading: '',
        // 乙方联系电话-----
        partBPhone: '',
        // 合同开工日期
        planBeginDate: '',
        // 合同竣工日期
        planOverDate: '',
        // 合同金额
        heTongMoney: '',
        // 计价方式
        valuationId: '',
        // 经办人
        createEmployeeId: '',
        // 经办部门
        deptId: '',
        // 签约日期
        // 是否申请盖章
        // 付款备注
        // 用印类型
        // 合同附件
      }
    };
  },
  methods: {

    // 附件上传
    handleRemove (file, fileList) {
      console.log(file, fileList);
    },
    handlePreview (file) {
      console.log(file);
    },
    handleExceed (files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove (file) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },

    // 保存
    keep () {
      this.$router.push('/contract/buildTeam')
    },


    // -----------------------------------------------------api-----------------------------------------
    // 回显
    getRowData () {
      this.contractId = this.$route.query.id
      this.$contractApi.getDetails(this.contractId).then(res => {
        if (res.data.code == 200) {
          console.log(res);
          this.contractForm = res.data.data[0];
          this.getList()
        }
      })
    },
    // 下拉框判断
    getList () {
      // 部门
      if (this.contractForm.deptName == '安防管理中心') {
        this.contractForm.deptId = 1
      } else if (this.contractForm.deptName == '人事行政部') {
        this.contractForm.deptName = 2
      } else if (this.contractForm.deptName == '人事部') {
        this.contractForm.deptName = 3
      } else if (this.contractForm.deptName == '培训科') {
        this.contractForm.deptName = 4
      } else if (this.contractForm.deptName == '行政部') {
        this.contractForm.deptName = 5
      } else if (this.contractForm.deptName == '安全中心') {
        this.contractForm.deptName = 6
      }
      // 关联项目
      if (this.contractForm.projectName == '苏州地铁项目') {
        this.contractForm.relation = 1
      } else if (this.contractForm.projectName == '北京地铁项目') {
        this.contractForm.relation = 2
      } else if (this.contractForm.projectName == '成都博物馆项目') {
        this.contractForm.relation = 3
      } else if (this.contractForm.projectName == '浙江轻轨项目') {
        this.contractForm.relation = 4
      }
      // 施工班组
    },
    getRelation () {
      this.$contractApi.relationSelect().then(res => {
        if (res.data.code == 200) {
          this.relationList = res.data.data
        }
      })
    },
  },
  created () {

  },
  mounted () {
    this.getRowData();
    console.log(this.relationList);
  },
  computed: {

  }
};
</script>

<style scoped lang="less">
</style>
